#include <iostream>
#include <deque>
#include <vector>

using std::cout;
using std::endl;
using std::deque;
using std::vector;

template <typename Container>
void display(const Container &con)
{
    for(auto &elem : con)
    {
        cout << elem << "  ";
    }
    cout << endl;
}

void test()
{
    deque<int> number = {1, 4, 6, 8, 9, 10, 5, 7};
    display(number);

    cout << endl << "在deque的尾部进行插入与删除" << endl;
    number.push_back(22);
    number.push_back(33);
    display(number);
    number.pop_back();
    display(number);

    cout << endl << "在deque的头部进行插入与删除" << endl;
    number.push_front(100);
    number.push_front(200);
    display(number);
    number.pop_front();
    display(number);

    cout << endl << "在deque的任意位置进行插入" << endl;
    auto it = number.begin();
    it += 2;
    cout << "*it = " << *it <<endl;
    number.insert(it, 111);
    display(number);
    cout << "*it = " << *it <<endl;

    cout << endl << endl;
    number.insert(it, 3, 200);
    display(number);
    cout << "*it = " << *it <<endl;

    cout << endl << endl;
    vector<int> vec = {333, 555, 444};
    number.insert(it, vec.begin(), vec.end());
    display(number);
    cout << "*it = " << *it <<endl;

    cout << endl << endl;
    number.insert(it, {123, 789, 456});
    display(number);
    cout << "*it = " << *it <<endl;
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

